package com.zhong.gang.pda.ui.mine;

import com.zhong.gang.applib.utils.ActivityController;
import com.zhong.gang.applib.http.BaseDataBean;
import com.zhong.gang.applib.http.callback.DataCallBack;
import com.zhong.gang.pda.api.Api;
import com.zhong.gang.pda.api.HttpUtils;
import com.zhong.gang.pda.db.user.UserUtils;
import com.zhong.gang.pda.ui.login.LoginAct;
import com.zhong.gang.pda.ui.main.MainActivity;

public class MinePresenter {
    /**
     * 退出登陆
     */
    public void loginOut(MineAct act){
        HttpUtils.post(Api.loginOut,act)
                .addParams("token", UserUtils.getIntent(act).getUser().getToken())
                .build().execute(act,"退出登录",new DataCallBack<BaseDataBean>(act){
            @Override
            public void onResponse(BaseDataBean data) throws Exception {
                super.onResponse(data);
                if (data.getCode() == 200){
                    UserUtils.getIntent(act).getUserDao().deleteAll();
                    act.openActivity(LoginAct.class);
                    ActivityController.getInstance().closeAct(MineAct.class);
                    ActivityController.getInstance().closeAct(MainActivity.class);
                }
            }
        });
    }
}
